#include "openfilelocatefileuploadui.h"

/**
 * @brief 构造函数
 */
OpenFileLocateFileUploadUI::OpenFileLocateFileUploadUI(QWidget *parent)
    : QQuickWidget(parent)
{
    // 初始化
    this->setResizeMode(QQuickWidget::SizeRootObjectToView);
    this->setFixedSize(656, 505);
    // this->setMaximumSize(656, 505);
    // this->setMinimumSize(656, 505);
    this->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
    this->setWindowTitle("");

    this->webAddUI = new OpenFileLocateFileUploadWebAddUI();
    this->_rootContext = this->getContext();
    // 传入ModelConfigNewUI类
    this->rootContext()->setContextProperty("openFileLoacteFile", this);
    // 资源加载
    this->setSource(QUrl("qrc:/OpenFileLocateFileUpload.qml"));
    this->_rootObj = this->getRootObject();
    if(_rootObj)
    {
        // 取消
        connect(_rootObj, SIGNAL(cancel()), this, SLOT(onCancel()));
        connect(_rootObj, SIGNAL(webAdd()), this, SLOT(onWebAdd()));
    }
}

/**
 * @brief 析构函数
 */
OpenFileLocateFileUploadUI::~OpenFileLocateFileUploadUI() {}

/**
 * @brief getContext 获取qmlcontext
 * @return qmlContext
 */
QQmlContext* OpenFileLocateFileUploadUI::getContext() const
{
    return this->rootContext();
}

/**
 * @brief getRootObject 获取rootObject
 * @return rootObject
 */
QObject* OpenFileLocateFileUploadUI::getRootObject() const
{
    return (QObject*)this->rootObject();
}

/**
 * @brief 取消
 */
void OpenFileLocateFileUploadUI::onCancel()
{
    this->close();

    this->update();
    QQuickWidget::update();
    // this->setVisible(false);

    qDebug() << "locatevisible";

    emit OpenFileLocateFileUploadUI::cancel();
}

/**
 * @brief 网络添加
 */
void OpenFileLocateFileUploadUI::onWebAdd()
{
    this->webAddUI->show();
}

void OpenFileLocateFileUploadUI::closeEvent(QCloseEvent *event)
{
    qDebug() << "closeEvent执行";

    return QQuickWidget::closeEvent(event);
}
